from django.db import models
from apps.users.models import User
from crum import get_current_user


class GenericModel(models.Model):
    updated_at = models.DateTimeField(
        auto_now=True,
        null=True,
        editable=False,
        verbose_name=u'Updated at',)
    created_at = models.DateTimeField(
        auto_now_add=True,
        editable=False,
        null=True,
        verbose_name=u'Created at')
    # updated_by = models.ForeignKey(
    #     User, editable=False,
    #     blank=True, null=True,
    #     on_delete=models.CASCADE,
    #     related_name="%(app_label)s_%(class)s_updated_by",
    #     verbose_name=u'Updated By')
    # created_by = models.ForeignKey(
    #     User,
    #     editable=False,
    #     blank=True,
    #     null=True,
    #     on_delete=models.CASCADE,
    #     related_name="%(app_label)s_%(class)s_created_by",
    #     verbose_name='Created By')

    def save(self, *args, **kwargs):
        # user = get_current_user()
        # if self._state.adding and isinstance(user, User):
        #     self.created_by = user
        # elif isinstance(user, User):
        #     self.updated_by = user

        super(GenericModel, self).save(*args, **kwargs)

    class Meta:
        abstract = True
